package com.lzx.resumeweb.api;

import com.lzx.resumebase.model.Project;
import com.lzx.resumebase.model.Result;
import com.lzx.resumebase.util.ResultUtil;
import com.lzx.resumeservice.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ProjectApi
 * @Author 刘正星
 * @Date 2021/6/2 下午11:13
 * @Description
 */
@RestController
@RequestMapping("/project")
public class ProjectApi {
    @Autowired
    private ProjectService projectService;

    @GetMapping("/getByUserId/{userId}")
    public Result get(@PathVariable("userId")String userId){
        if (!StringUtils.hasText(userId)){
            ResultUtil.paramError();
        }
        return  ResultUtil.success(projectService.lambdaQuery().eq(StringUtils.hasText(userId), Project::getUserId,userId).list());
    }

    @GetMapping("/getByWorkId/{Id}")
    public Result getByWork(@PathVariable("Id")String id) {
        if (!StringUtils.hasText(id)) {
            ResultUtil.paramError();
        }
        return ResultUtil.success(projectService.lambdaQuery().eq(StringUtils.hasText(id), Project::getWorkId, id).list());
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable("id")String id){
        if (!StringUtils.hasText(id)){
            return ResultUtil.paramError();
        }
        return ResultUtil.success(projectService.getById(id));
    }

}
